package com.qiniu.githubdata.controller;

import com.qiniu.githubdata.common.Result;
import com.qiniu.githubdata.entity.Repository;
import com.qiniu.githubdata.service.RepositoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @Author: mayixiang
 * @Date: 2024-11-06 11:55
 * @Description:
 */
@RestController
@RequestMapping("/repository")
public class RepositoryController {
    @Resource
    private RepositoryService repositoryService;
    @GetMapping("/top6/{owner}")
    public Result<List<Repository>> getTop6Repositories(@PathVariable String owner) {
        List<Repository> repositories = null;
        try {
            repositories = repositoryService.getTop6RepoByOwner(owner);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return Result.success(repositories);
    }

}
